package com.libra.assemble.xutil.Idcard;

import com.libra.assemble.xutil.Utils;
import com.libra.assemble.xutil.enums.Gender;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.persistence.Enumerated;

/**
 * 身份证的相关信息.
 * 
 * @author Libra
 *
 */
public class IdCardForm {

	/** 身份证号 */
	private String idcard;

	/** 性别 */
	private Gender gender;

	/** 出生年月日 格式：yyyy-MM-DD*/
	private String birthday;

	/** 籍贯：格式 省 */
	private String province;

	/** 籍贯：格式 市 */
	private String city;

	/** 籍贯：格式 县 */
	private String county;

	public String getIdcard() {
		return idcard;
	}

	public void setIdcard(String idcard) {
		this.idcard = idcard;
	}

	@Enumerated
	public Gender getGender() {
		return gender;
	}

	public void setGender(Gender gender) {
		this.gender = gender;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCounty() {
		return county;
	}

	public void setCounty(String county) {
		this.county = county;
	}

	/**
	 * 根据出生取得年龄.
	 * @return
	 */
	public Integer getAge() {
		if (birthday != null) {
			return Utils.getAgeByBirthday(Utils.parseDate(birthday));
		} else {
			return null;
		}
	}

	/**
	 * 覆盖toString方法，目的显示所有JavaBean的属性值，省略写很多的getXxx的方法
	 */
	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.MULTI_LINE_STYLE);
	}
}
